import { store } from '@/utils/store'
import { call } from '@/utils/request'
import { showMsg, showSuccess, showLoading } from '@/utils/toast'

Page({
  data: {
    isAgree: false,
    to_page: ''
  },
  onLoad(option) {
    this.setData({
      to_page: option.to_page
    })
  },
  clickRadio() {
    this.setData({
      isAgree: !this.data.isAgree
    })
  },
  clickSubmit() {
    showMsg("请阅读并勾选下列协议~")
  },
  getPhoneNumber(e) {
    if (e.detail.code) {
      showLoading()
      call('/loginByWxMobile/'+e.detail.code).then(res => {
        store.set_user_info(res, true)
        const duration = showSuccess("登录成功！")
        setTimeout(()=>{
          if (this.data.to_page) {
            wx.redirectTo({
              url: decodeURIComponent(this.data.to_page),
            })
          } else {
            wx.navigateBack()
          }
        }, duration)
      })
    }
  },
})
